package web.suzy.oj.controller.admin;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.user.Session;
import web.suzy.oj.service.admin.system.DashboardService;

import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: DashboardController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/30 10:55
 */
@RestController
@RequestMapping("/api/admin/dashboard")
public class DashboardController {
    @Autowired
    private DashboardService dashboardService;

    /**
     * 方法名: getRecentSession
     * 描述: 获取该登录账号下的最近会话
     *
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.entity.user.Session>
     * @date 2022/11/30 10:55
     * @auther YangSuzy
     **/
    @PostMapping("/get-sessions")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Session> getRecentSession() {
        return dashboardService.getRecentSession();
    }

    /**
     * 方法名: getDashboardInfo
     * 描述: 获取工作台信息
     *
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/11/30 11:06
     * @auther YangSuzy
     **/
    @GetMapping("/get-dashboard-info")
    @RequiresAuthentication
    @RequiresRoles(value = {"root","admin","problem_admin"},logical = Logical.OR)
    public ResultBean<Map<Object, Object>> getDashboardInfo() {
        return dashboardService.getDashboardInfo();
    }
}
